package com.qf.result;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.status.StatusCode;

/*
*@Description:自定义封装返回结果
*@author:刘哥
*@Date:86180 2022/8/31 19:41
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)//属性值为空时不输出
public class Result {
    private int code;//状态码
    private String msg;//状态信息
    private Object data;//数据

    public static Result OK(){
        return OK(null);
    }
    public static Result OK(Object data){
        return getResult(StatusCode.SUCCESS,"成功",data);
    }
    public static Result OK(int code,String msg,Object data) {
        return getResult(StatusCode.SUCCESS,"成功",null);
    }
    public static Result ERROR(){
        return ERROR(null);
    }
    public static  Result ERROR(Object data){
        return getResult(StatusCode.FAIL, "失败", data);
    }
    public static Result getResult(int code,String msg){
        return getResult(code, msg,null);
    }
    public static Result getResult(int code,String msg,Object data){
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }



    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
